local ma__zhuifeng = fk.CreateSkill {
  name = "ma__zhuifeng",
  tags = { Skill.Compulsory, Skill.Switch },
}

Fk:loadTranslationTable{
  ["ma__zhuifeng"] = "追锋",
  [":ma__zhuifeng"] = "锁定技，转换技，当你使用牌后，你摸两张牌，然后直到你下回合开始，阳：你不能再使用点数大于此牌的牌："..
  "阴：你不能再使用点数小于此牌的牌。",

  ["@ma__zhuifeng"] = "追锋",
}

ma__zhuifeng:addEffect(fk.CardUseFinished, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ma__zhuifeng.name)
  end,
  on_cost = function(self, event, target, player, data)
    event:setCostData(self, { tos = { data.to } })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, ma__zhuifeng.name)
    if data.card and data.card.number > 0 and data.card.number < 14 then
      local number1,number2 = 1,13
      if player:getSwitchSkillState(ma__zhuifeng.name, true) == fk.SwitchYang then
        number2 = data.card.number
      else
        number1 = data.card.number
      end
      if number1 > number2 then
        number1, number2 = number2, number1
      end
      if player:getMark("ma__zhuifeng") ~= 0 then
          number1 = math.max(number1, player:getMark("ma__zhuifeng")[1])
          number2 = math.min(number2, player:getMark("ma__zhuifeng")[2])
      end
      room:setPlayerMark(player, "ma__zhuifeng", {number1, number2})
      room:setPlayerMark(player, "@ma__zhuifeng", number1..", "..number2)
    end
  end,
})

ma__zhuifeng:addEffect(fk.TurnStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "ma__zhuifeng", 0)
    player.room:setPlayerMark(player, "@ma__zhuifeng", 0)
  end,
})

ma__zhuifeng:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if card then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      if #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end) then
        if player:getMark("ma__zhuifeng") ~= 0 then
          for _, id in ipairs(subcards) do
            local c = Fk:getCardById(id)
            if c.number < player:getMark("ma__zhuifeng")[1] or c.number > player:getMark("ma__zhuifeng")[2] then
              return true
            end
          end
        end
      end
    end
  end,
})

return ma__zhuifeng